<style type="text/css" media="screen">
.t_judul{
        
        padding:12px;
        font-size:16px;
        font-weight:bold;
        margin-bottom: 10px;
        padding-bottom: 20px;
}

.t_header{
        background:#dddddd;
        vertical-align: middle;
        padding:3px;
        text-align: center;
        border: solid 1px;
        font-weight: bold;
}

.t_isi{
        vertical-align: middle;
        padding:3px;
        border: solid 1px;
        font-weight: bold;
}

<!--
.container {min-width: 170px; margin: 0px auto;position: fixed; right: 0px; top: 0px;}
.messagebox {background-color: #F5F5F5;padding:0px;margin:0px;border: 1px solid #DBDBDB;}
.errorbox {color:#000;background-color:#f96d07;padding:5px;margin:10px 0px;border:1px solid #f27c7c;font-weight:bold;color:white;}
.confirmbox {background-color:#F2FFDB;color:#151515;border:1px solid #9C6;margin:10px 0px;padding:5px;}
-->
</style>

<div class="container">
<div class="messagebox" id="messageBox"></div>
</div>

<script>
$(document).ready(function() {
    $(".divAgent").hide();
    $('.d_journey').live("click",function() {
        var sfa        = $(this).attr('sfa');
        var outlet     = $(this).attr('outlet');
        var tgl        = $(this).attr('tgl');
        var tanggal        = $(this).attr('tanggal');
        var bulan      = $(this).attr('bulan');
        var nilai      = $(this).is(':checked');
        var jmlkunjungan= $("#jml_total").attr('value');
        var kunjunganoutlet = $("#jml_o" + outlet).attr('value');
        
        $.post(
            '<?=base_url()?>index.php/journey_cycle/saveJC_sgs', 
            {sfa:sfa,outlet:outlet,tgl:tgl,bulan:bulan,nilai:nilai,tanggal:tanggal,jmlkunjungan:jmlkunjungan,kunjunganoutlet:kunjunganoutlet},
            function(data) {
                if(data.status == 'OK'){
                        $("#messageBox").removeClass().addClass("errorbox").html(data.pesan).fadeIn(1000).fadeOut(1000);
                        document.getElementById("jml"+ tgl).innerHTML = data.kunjungan;
                        
                        $("#jml_o" + outlet).val(data.kunjunganoutlet);
                        $("#jml_total").val(data.totalkunjungan);
                }
            },
            "json"
        ).error(function() {
            alert("-");
        });
    });
    
    $('.d_copy_journey').live("click",function() {
        var bulan        = $(this).attr('bulan');
        var tahun     = $(this).attr('tahun');
        var sfa        = $(this).attr('sfa');
        
        $.post(
            '<?=base_url()?>index.php/journey_cycle/copySGS', 
            {sfa:sfa,bulan:bulan,tahun:tahun},
            function(data) {
                if(data.status == 'OK') {
                    alert(data.pesan);
                }
            },
            "json"
        ).error(function() {
            alert("-");
        });
    });
    
    $('.sfa').change(function() {
        var tipe_penjualan         = $("#tipe_penjualan").attr('value');
        var sfa = $("#sfa").attr('value');
        var bulan       = $("#bulan").attr('value');
        var statusagent = $("#status").attr('value');
        $(".divAgent").hide();
        $.post(
            '<?=base_url()?>index.php/journey_cycle/get_jc_sgs', 
            {sfa:sfa,tipe_penjualan:tipe_penjualan,bulan:bulan,statusagent:statusagent},
            function(data) {
                if(data.status == 'OK'){
                        
                        if(data.jumlah==0){
                                //alert("Tidak ada data Journey Cycle DS");
                        }
                        
                        //document.getElementById("divJumlah").innerHTML = data.jumlah;
                        document.getElementById("divData").innerHTML   = data.datatabel;
                        //document.getElementById("divAgent").innerHTML  = data.agent;
                        if(data.agent == 'show'){
                                $(".divAgent").show();
                                reload( tipe_penjualan );
                        }else{
                                $(".divAgent").hide();
                        }
                        
                }
            },
            "json"
        ).error(function() {
            alert("-");
        });
    });
    
    $('.d_jc_sgs').change(function() {
        var tipe_penjualan         = $("#tipe_penjualan").attr('value');
        var sfa = $("#sfa").attr('value');
        var bulan       = $("#bulan").attr('value');
        var statusagent = $("#status").attr('value');
        $(".divAgent").hide();
        $.post(
            '<?=base_url()?>index.php/journey_cycle/get_jc_sgs', 
            {sfa:sfa,tipe_penjualan:tipe_penjualan,bulan:bulan,statusagent:statusagent},
            function(data) {
                if(data.status == 'OK'){
                        
                        if(data.jumlah==0){
                                //alert("Tidak ada data Journey Cycle DS");
                        }
                        
                        //document.getElementById("divJumlah").innerHTML = data.jumlah;
                        document.getElementById("divData").innerHTML   = data.datatabel;
                        //document.getElementById("divAgent").innerHTML  = data.agent;
                        if(data.agent == 'show'){
                                $(".divAgent").show();
                                reload( tipe_penjualan );
                        }else{
                                $(".divAgent").hide();
                        }
                        
                }
            },
            "json"
        ).error(function() {
            alert("-");
        });
    });
    
    $('.d_jc_sgs_status').change(function() {
        var tipe_penjualan         = $("#tipe_penjualan").attr('value');
        var sfa = $("#sfa").attr('value');
        var bulan       = $("#bulan").attr('value');
        var statusagent = $("#status").attr('value');
        $(".divAgent").hide();
        $.post(
            '<?=base_url()?>index.php/journey_cycle/get_jc_sgs', 
            {sfa:sfa,tipe_penjualan:tipe_penjualan,bulan:bulan,statusagent:statusagent},
            function(data) {
                if(data.status == 'OK'){
                        
                        if(data.jumlah==0){
                                //alert("Tidak ada data Journey Cycle DS");
                        }
                        
                        //document.getElementById("divJumlah").innerHTML = data.jumlah;
                        document.getElementById("divData").innerHTML   = data.datatabel;
                        //document.getElementById("divAgent").innerHTML  = data.agent;
                        if(data.agent == 'show'){
                                $(".divAgent").show();
                                reload( tipe_penjualan );
                        }else{
                                $(".divAgent").hide();
                        }
                        
                }
            },
            "json"
        ).error(function() {
            alert("-");
        });
    });
    
    $('.add_agent_sgs').click(function() {
        var sfa         = $("#sfa").attr('value');
        var bulan       = $("#bulan").attr('value');
        var c_agent = new Array();
        c_agent = $('#cc').combogrid('getValues');
         
        $.post(
            '<?=base_url()?>index.php/journey_cycle/add_agent_sgs', 
            {sfa:sfa,bulan:bulan,c_agent:c_agent},
            function(data) {
                if(data.status == 'OK'){
                        //document.getElementById("divJumlah").innerHTML = data.jumlah;
                        document.getElementById("divData").innerHTML   = data.datatabel;
                }
            },
            "json"
        ).error(function() {
            alert("-");
        });
    });
    
});

$(document).ready(function() {
	$("#messageBox").addClass("messagebox");setTimeout(function(){
		$("#messageBox").fadeOut("slow")}, 3000);
	});
function messagebox(){
	$("#messageBox").removeClass().addClass("confirmbox").html("Item has been saved").fadeIn(2000).fadeOut(6000);
}
function alertbox(){
	$("#messageBox").removeClass().addClass("errorbox").html("Oops, there was an error!").fadeIn(2000).fadeOut(6000);
}


function getMultipleSelection(formName,elementName,array){ 
    var selected = new Array();
    var mySelect = "";
    mySelect = document.forms[formName].elements[elementName]; 
    for(j = 0; j < mySelect.options.length; j++) { 
        if(mySelect.options[j].selected) { 
            selected.push(mySelect.options[j].value); 
        } 
    } 
    if(array != 'true') return selected.toString(); 
    else return selected; 
} 
</script>

<script>
        $(function(){
                
        });
        function reload( idnya ){
                $('#cc').combogrid({
                        panelWidth:450,
                        value:'006',

                        idField:'id',
                        textField:'name',
                        multiple:'true',
                        nowrap: false,
                        striped: true,
                        separator:',',
                        frozenColumns:[[
                                {field:'ck',checkbox:true}
                        ]],
                        
                        url:'<?=base_url()?>index.php/journey_cycle/toko_json/' + idnya ,
                        columns:[[
                                {field:'id',title:'ID',width:100},
                                {field:'name',title:'Toko/Lokasi',width:140},
                                {field:'city',title:'Alamat',width:120}
                        ]]
                });
        }
        function setValue(){
                $('#cc').combogrid('setValue', '002');
        }
        function getValue(){
                var val = $('#cc').combogrid('getValue');
                alert(val);
        }
        function disable(){
                $('#cc').combogrid('disable');
        }
        function enable(){
                $('#cc').combogrid('enable');
        }
</script>

<script type="text/javascript" src="<?=base_url()?>file/smooth/js/jquery-1.4.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="<?=base_url()?>file/js/easyui/themes/gray/easyui.css">
<link rel="stylesheet" type="text/css" href="<?=base_url()?>file/js/easyui/themes/icon.css">
<script type="text/javascript" src="<?=base_url()?>file/js/easyui/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="<?=base_url()?>file/js/easyui/jquery.easyui.min.js"></script>

<div class="box" style="min-height:700px;">
        <!-- box / title -->
        <div class="title">
                <h5>Journey Cycle :: SGS</h5>
                <ul class="links">
                        <!-- <li><a href="<?=base_url()."index.php/".$this->uri->segment(1)?>/direct_sales">Direct Sales</a></li>
                        <li><a href="<?=base_url()."index.php/".$this->uri->segment(1)?>/smartfren_ambassador">SmartFren Ambassador</a></li> -->
                </ul>
        </div>
        <!-- end box / title -->
        
        <form id="form" name="form action="<?=$_SERVER['PHP_SELF']?>" method="post">
                <div class="form">
                        <div class="fields">
                                
                                <div class="field">
                                        <div class="label" style="padding-top:0;">
                                                <label for="region">Path Territori:</label>
                                        </div>
                                        <div class="input">
                                                <label id="region"><b><?=$this->mglobal->getTerritoryPath()?></b></label>
                                        </div>
                                </div>
                                
                                <div class="field">
                                        <div class="label">
                                                <label for="name">Sales :</label>
                                        </div>
                                        <div class="input" id="divDS0">
                                                <select name="sfa" id="sfa" class="sfa">
                                                <?php
                                                echo'<option value="">-Pilih-</option>';
                                                $getds = $this->mglobal->getSGS();
                                                //$getds = $this->mglobal->getDS();
                                                foreach($getds as $r){
                                                        echo'<option value="'.$r->mvalue.'">'.$r->mdisplay.'</option>';
                                                }
                                                echo'</select>';
                                                ?>                                                
                                        </div>
                                </div>
                                
                                <div class="field">
                                        <div class="label">
                                                <label for="name">Tipe Penjualan :</label>
                                        </div>
                                        <div class="input">
                                                <select name="tipe_penjualan" id="tipe_penjualan" class="d_jc_sgs">
                                                <?php
                                                $getdata = $this->mjourney->getTipePenjualanSGS();
                                                foreach($getdata as $r){
                                                        echo'<option value="'.$r->mvalue.'">'.$r->mdisplay.'</option>';
                                                }
                                                echo'</select>';
                                                ?>
                                        </div>
                                </div>
                                
                                <div class="field">
                                        <div class="label">
                                                <label for="name">Pilih Bulan:</label>
                                        </div>
                                        <div class="input">
                                                
                                                <select name="bulan" id="bulan" class="d_jc_sgs">
                                                <?php
                                                echo'<option value="">-Pilih-</option>';
                                                for($b=1;$b<=12;$b++){
                                                        echo'<option value="'. date("m", mktime(0,0,0,$b,1,2012)) .'" name="bulan">'. date("F", mktime(0,0,0,$b,1,2012)) .' '. date('Y') .'</option>';
                                                }
                                                ?>
                                                </select>
                                        </div>
                                </div>
                                
                                <div class="divAgent">
                                        
                                        <div class="field">
                                                <div class="label" style="padding-top:0;">
                                                        <label>Pilih Lokasi/Toko:</label>
                                                </div>
                                                <div class="input">
                                                        <select name="c_agent" id="cc" style="width:250px;" multiple="true" readonly cascadeCheck="false"></select>
                                                </div>
                                        </div>
                                        
                                        <div class="buttons">
                                                <input type="button" value="Masukkan Lokasi/Toko" class="add_agent_sgs" />
                                        </div>
                                        
                                </div>
                                
                                
                        </div>
                </div>
        </form><br><br>&nbsp;
        
        <div id="divData" style="width: 98%;"></div>
</div>